<template>
  <div class="drawerMain">
    <div class="orderNo-box">
      <h4>订单编号：{{ orderInfo.orderNo }}</h4>
      <el-badge :value="unread" class="item" :hidden="!unread">
        <svg-icon icon-class="xx_icon_nor" @click="message" />
      </el-badge>
    </div>
    <!-- <h4>订单编号：{{orderInfo.orderNo}}</h4> -->

    <h3>订单信息</h3>
    <ul>
      <li>
        <span>订单类型</span>
        <p>{{ orderInfo.type == "6" ? "项目" : "咨询" }}</p>
      </li>
      <li>
        <span>订单金额</span>
        <p>{{ orderInfo.amount | sumFilters }}</p>
      </li>
      <li>
        <span>创建时间</span>
        <p>{{ orderInfo.createdTime }}</p>
      </li>
      <li>
        <span>预计时间</span>
        <p>{{ orderInfo.endTime }}</p>
      </li>
      <!-- <li v-if="orderInfo.overdue">
        <span>逾期天数</span>
        <p>逾期{{ orderInfo.overdue }}天</p>
      </li> -->
      <li>
        <span>服务专家</span>
        <p>{{ orderInfo.expertName }}</p>
      </li>
      <li>
        <span>咨询问题</span>
        <p>{{ info.goods && info.goods.question }}</p>
      </li>
      <li v-if="info.goods && info.goods.questionAppend">
        <span>追问</span>
        <p>
          <b v-for="(question, index) in info.goods.questionAppend" :key="index"
            >追问{{ index + 1 }}：{{ question }}</b
          >
        </p>
      </li>
      <li v-if="info.goods && info.goods.files && info.goods.files.length > 0">
        <span>附件</span>
        <p>
          <a :href="file" v-for="(file, index) in info.goods.files" :key="index"
            >附件{{index+1}}：{{ file.substring(file.lastIndexOf("/") + 1) }}</a
          >
        </p>
      </li>
    </ul>

    <h3
      v-if="info.goods && info.goods.answers && info.goods.answers.length > 0"
    >
      解答（{{ info.goods.answers[0].content.length }}）
    </h3>

    <div
      class="awearItem-box"
      v-if="info.goods && info.goods.answers && info.goods.answers.length > 0"
    >
      <!-- answers循环 -->
      <div v-for="answer in info.goods.answers" :key="answer.id">
        <!-- content循环 -->
        <main
          class="comment-content"
          v-for="cont in answer.content"
          :key="cont.id"
        >
          <div class="title-box">
            <img class="img" :src="answer.avatar" />
            <div class="name">{{ answer.expertName }}</div>
            <div class="time">· {{ answer.createTime }}</div>
          </div>
          <div class="content-box">
            <p>{{ cont.answer }}</p>
          </div>

          <div
            class="law-box"
            v-for="(lawList, index) in cont.law"
            :key="index"
          >
            <div class="law-tile">{{ lawList.title }}</div>
            <!-- <div class="law-tile">法条依据{{index+1}}：《{{lawList.title}}》</div> -->

            <div class="law-content">
              <p v-for="(lawCont, index) in lawList.content" :key="index">
                {{ lawCont }}
              </p>
            </div>
          </div>

          <div class="file-box">
            <div
              class="file-list"
              v-for="fileList in cont.file"
              :key="fileList.url"
            >
              <i class="el-icon-document"></i>
              <p>附件：{{ fileList.name }}</p>
              <a :href="fileList.url">
                <svg-icon icon-class="download" />
              </a>
            </div>
          </div>
        </main>
        <!-- content循环 end-->
      </div>
      <!-- answers循环 end -->
    </div>
    <div class="ribbon_content" v-if="orderInfo.userId == $store.state.user.userId">
      <Ribbon></Ribbon>
    </div>
    <!-- 用户的结案按钮 -->
    <!-- <SubBtn v-if="orderInfo.status != '0' && (orderInfo.userId == $store.state.user.userId)">
      <template slot="btn">
        <div class="btn-box">
            <el-button round class="addBtn" @click="clickOverOrder">结案</el-button>
        </div>
      </template>
    </SubBtn> -->
  </div>
</template>

<script>
// import SubBtn from "@/components/subBtn/subBtn.vue"
import Ribbon from "../documentary/ribbon.vue";

import { getOrderGetInfoApi } from "@/BMViews/api/financial/order.js";
import { getMessageList } from "@/BMViews/api/upload/index.js";
import { overClosOrderApi } from "@/wss/newApi_3-24/work/documentary.js";
export default {
  props: {
    orderInfo: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  components: { Ribbon },
  data() {
    return {
      unread: 0, //未读信息数量
      info: {}, //当前订单的详细详细
    };
  },
  watch: {
    // 数据变化的时候
    orderInfo: {
      deep: true,
      handler(newValue, oldValue) {
        this.getOrderGetInfo(); // 获取订单详细信息
        // 获取当前订单的左上角未读信息
        this.getOrderMeetList();
      },
    },
  },
  mounted() {
    this.getOrderGetInfo(); // 获取订单详细信息
    // 获取当前订单的左上角未读信息
    this.getOrderMeetList();
    //接受订单子组件的回调
    this.$bus.$on("refreshQuestion", () => {
      this.getOrderGetInfo();
    });
  },
  methods: {
    // 获取订单详细信息
    async getOrderGetInfo() {
      let id = this.orderInfo.id;
      let result = await getOrderGetInfoApi({ id });
      if (result.code == 200) {
        this.info = result.data;
        this.$bus.$emit("oderdetail", this.info, this.info.type);
      }
    },

    // 项目未读信息的接口
    async getOrderMeetList() {
      let result = await getMessageList();
      if (result.code == 200) {
        let list = result.data.rows;
        let unrObj = list.find((itme) => {
          return itme.id == this.orderInfo.orderNo;
        });
        this.unread = 0; //清除之前的聊天
        if (unrObj.unread) {
          this.unread = unrObj.unread;
        }
      }
    },

    // 点击聊天按钮
    message() {
      // 跳转到当前项目的聊天页面
      this.$router.push({
        path: "/Bm-personalCenter/messageCenter",
        query: { orderId: this.orderInfo.orderNo },
      });
    },

    // 点击结束订单
    clickOverOrder() {
      this.overClosOrder(this.orderInfo);
    },

    // 咨询订单点击结束订单的接口 (结束咨询订单的接口)
    async overClosOrder(data) {
      let result = await overClosOrderApi(data);
      if (result.code == 200) {
        this.$message({ message: "操作成功", type: "success" });
      }
    },
  },
};
</script>

<style scoped>
h3,
h4,
p,
ul,
li {
  margin: 0;
  padding: 0;
}
/* 订单详情 */
.drawer-title {
  font-size: 12px;
  font-weight: 400;
  color: #99a2b1;
}
.drawerMain {
  padding: 0 30px;
}
.drawerMain h4 {
  padding: 10px 15px;
  background-color: #f4f5f8;
  font-size: 12px;
  font-weight: 400;
  color: #2e3f5e;
}

.orderNo-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background-color: #f4f5f8;
}
.orderNo-box .svg-icon {
  font-size: 24px;
  /* padding: 5px; */
  margin: 10px 20px;
  cursor: pointer;
}
>>> .orderNo-box .el-badge__content.is-fixed {
  position: absolute;
  top: 15px;
  right: 30px;
  transform: translateY(-50%) translateX(100%);
}

.drawerMain h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2e3f5e;
  margin-bottom: 20px;
  margin-top: 30px;
}
.drawerMain ul {
  border-bottom: 1px solid #efefef;
}
.drawerMain li {
  display: flex;
  /* align-items: center; */
  flex-wrap: wrap;
  font-size: 14px;
  line-height: 20px;
  margin-bottom: 15px;
}
.drawerMain li > span {
  display: block;
  width: 15%;
  color: #999999;
}
.drawerMain li > p {
  flex:0 0 85%;
  font-size: 14px;
  font-weight: 400;
  color: #222;
}
.drawerMain li > p > b {
  display: block;
  font-weight: 400;
  margin-bottom: 5px;
}
.drawerMain li > p > a {
  display: block;
  color: #f87a23;
  margin-bottom: 15px;
}
/* 订单详情 end*/

/* 底部按钮 */
::v-deep .subBtn {
  padding: 10px 30px;
  align-items: center;
}
</style>
<style lang="scss" scoped>
// 解答样式
.awearItem-box {
  padding-bottom: 80px;
  .title-box {
    display: flex;
    align-items: center;
    img {
      height: 32px;
      width: 32px;
      border-radius: 50%;
    }
    .name {
      font-size: 14px;
      font-weight: 800;
      margin: 0 8px 0 10px;
    }
    .time {
      font-size: 12px;
      color: #999;
    }
    margin-bottom: 15px;
  }
  .comment-content {
    font-size: 14px;
    margin-bottom: 30px;
    .content-box {
      margin: 15px 0;
      line-height: 24px;
    }
  }

  .law-box {
    // font-weight: 800;
    color: #868fa3;
    background-color: #f6f7fa;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 10px;
    .law-tile {
      font-weight: bold;
      margin-bottom: 10px;
    }
    .law-content {
      padding: 0px;
      font-size: 14px;
      line-height: 24px;
      p {
        margin-bottom: 10px;
      }
      p:last-child {
        margin-bottom: 0px;
      }
    }
  }

  .file-box {
    margin: 15px 0;
    .file-list {
      display: flex;
      align-items: center;
      color: #666;
      border-radius: 8px;
      border: 1px solid #efefef;
      padding: 10px 15px;
      margin-bottom: 10px;
      i {
        margin-right: 10px;
      }
      a {
        font-size: 20px;
        margin-left: auto;
      }
    }
  }
}
/* 功能区 */
.ribbon_content {
  position: absolute;
  left: 0;
  bottom: 0px;
  width: calc(100%);
  background-color: #fff;
  border-top: 1px solid #ecedf0;
}
</style>
